class AIAssistant:
    """AI助手基类"""

    def __init__(self, assistant_id, name, assistant_type, version, online, score):
        self.id = assistant_id
        self.name = name
        self.type = assistant_type
        self.version = version
        self.online = online
        self.score = score

    def perform_task(self, task):
        """执行任务"""
        if not self.online:
            return f"❌ {self.name} 当前离线，无法执行任务。"
        return f"✅ {self.name} 正在执行任务: {task}"

    def get_status(self):
        """获取状态字符串"""
        return "🟢在线" if self.online else "🔴离线"

    def __str__(self):
        return f"ID: {self.id}, 名称: {self.name}, 类型: {self.type}, 版本: {self.version}, 状态: {self.get_status()}, 能力评分: {self.score} [{self.type}]"


class DataAnalysisAssistant(AIAssistant):
    """数据分析助手"""

    def __init__(self, assistant_id, name, version, online, score, data_processing_speed):
        super().__init__(assistant_id, name, "数据分析助手", version, online, score)
        self.data_processing_speed = data_processing_speed

    def __str__(self):
        return super().__str__() + f", 数据处理速度: {self.data_processing_speed}"


class ImageGenerationAssistant(AIAssistant):
    """图片生成助手"""

    def __init__(self, assistant_id, name, version, online, score, image_quality):
        super().__init__(assistant_id, name, "图片生成助手", version, online, score)
        self.image_quality = image_quality

    def __str__(self):
        return super().__str__() + f", 图片质量: {self.image_quality}"


class TextGenerationAssistant(AIAssistant):
    """文本生成助手"""

    def __init__(self, assistant_id, name, version, online, score, writing_style):
        super().__init__(assistant_id, name, "文本生成助手", version, online, score)
        self.writing_style = writing_style

    def __str__(self):
        return super().__str__() + f", 写作风格: {self.writing_style}"


class TranslationAssistant(AIAssistant):
    """翻译助手"""

    def __init__(self, assistant_id, name, version, online, score, supported_languages):
        super().__init__(assistant_id, name, "翻译助手", version, online, score)
        self.supported_languages = supported_languages

    def __str__(self):
        return super().__str__() + f", 支持语言数: {self.supported_languages}"


class VoiceAssistant(AIAssistant):
    """语音助手"""

    def __init__(self, assistant_id, name, version, online, score, voice_type):
        super().__init__(assistant_id, name, "语音助手", version, online, score)
        self.voice_type = voice_type

    def __str__(self):
        return super().__str__() + f", 语音类型: {self.voice_type}"


class AIManager:
    """AI助手管理器"""

    def __init__(self):
        self.assistants = []
        self.max_size = 100
        self._add_example_assistants()

    def _add_example_assistants(self):
        """添加示例助手"""
        self.assistants.append(VoiceAssistant("101", "小智", "v1.2", True, 85, "甜美"))
        self.assistants.append(TextGenerationAssistant("102", "文小助", "v2.0", True, 92, "正式"))
        self.assistants.append(ImageGenerationAssistant("103", "图灵", "v1.5", False, 88, "高清"))
        self.assistants.append(DataAnalysisAssistant("104", "数小析", "v1.0", True, 79, "快速"))
        self.assistants.append(TranslationAssistant("105", "翻译精灵", "v2.1", False, 95, 50))

    def list_all_assistants(self):
        """查看所有AI助手列表"""
        print("所有AI助手列表：")
        if not self.assistants:
            print("暂无AI助手数据。")
            return

        for i, assistant in enumerate(self.assistants, 1):
            print(f"{i}. {assistant}")

    def find_assistant_by_id(self, assistant_id):
        """根据ID查询助手详情"""
        for assistant in self.assistants:
            if assistant.id == assistant_id:
                print(f"✅ 查询结果: {assistant}")
                return
        print(f"❌ 未找到ID为 {assistant_id} 的AI助手。")

    def add_assistant(self, assistant):
        """添加新的AI助手"""
        if len(self.assistants) >= self.max_size:
            print("❌ 助手数量已达上限，无法添加新助手。")
            return

        # 检查ID是否已存在
        for a in self.assistants:
            if a.id == assistant.id:
                print(f"❌ 已存在ID为 {assistant.id} 的助手。")
                return

        self.assistants.append(assistant)
        print(f"✅ 助手【{assistant.name}】添加成功！")

    def update_assistant(self, assistant_id, field, value):
        """根据ID修改助手信息"""
        for assistant in self.assistants:
            if assistant.id == assistant_id:
                try:
                    if field.lower() == "name":
                        assistant.name = value
                    elif field.lower() == "type":
                        assistant.type = value
                    elif field.lower() == "version":
                        assistant.version = value
                    elif field.lower() == "online":
                        assistant.online = value == "1" or value.lower() == "true"
                    elif field.lower() == "score":
                        assistant.score = int(value)
                    else:
                        print(f"❌ 无效的属性名: {field}")
                        return

                    print(f"✅ 助手【{assistant_id}】修改成功！")
                except Exception as e:
                    print(f"❌ 修改失败: {e}")
                return

        print(f"❌ 未找到ID为 {assistant_id} 的AI助手。")

    def delete_assistant(self, assistant_id):
        """删除AI助手（按ID）"""
        for i, assistant in enumerate(self.assistants):
            if assistant.id == assistant_id:
                name = assistant.name
                del self.assistants[i]
                print(f"✅ 助手【{name}】已删除。")
                return

        print(f"❌ 未找到ID为 {assistant_id} 的AI助手。")

    def start_assistant(self, assistant_id):
        """启动AI助手服务"""
        for assistant in self.assistants:
            if assistant.id == assistant_id:
                if assistant.online:
                    print(f"助手【{assistant.name}】已在运行。")
                else:
                    assistant.online = True
                    print(f"✅ 助手【{assistant.name}】已启动。")
                return

        print(f"❌ 未找到ID为 {assistant_id} 的AI助手。")

    def stop_assistant(self, assistant_id):
        """停止AI助手服务"""
        for assistant in self.assistants:
            if assistant.id == assistant_id:
                if not assistant.online:
                    print(f"助手【{assistant.name}】已停止。")
                else:
                    assistant.online = False
                    print(f"✅ 助手【{assistant.name}】已停止。")
                return

        print(f"❌ 未找到ID为 {assistant_id} 的AI助手。")

    def assign_task(self, assistant_id, task):
        """为AI助手分配任务"""
        for assistant in self.assistants:
            if assistant.id == assistant_id:
                print(assistant.perform_task(task))
                return

        print(f"❌ 未找到ID为 {assistant_id} 的AI助手。")

    def show_statistics(self):
        """显示系统统计信息"""
        if not self.assistants:
            print("系统统计信息：\n暂无AI助手数据。")
            return

        online_count = sum(1 for assistant in self.assistants if assistant.online)
        total_score = sum(assistant.score for assistant in self.assistants)
        average_score = total_score / len(self.assistants)

        print("系统统计信息：")
        print(f"总助手数: {len(self.assistants)}")
        print(f"在线助手数: {online_count}")
        print(f"离线助手数: {len(self.assistants) - online_count}")
        print(f"平均能力评分: {average_score:.2f}")


def add_new_assistant(manager):
    """添加新助手"""
    print("添加新AI助手")
    assistant_id = input("请输入ID: ")
    name = input("请输入名称: ")
    print("请输入类型 (1-数据分析, 2-图片生成, 3-文本生成, 4-翻译, 5-语音): ")
    type_choice = input().strip()
    version = input("请输入版本号: ")
    online = input("是否在线？(1-是, 0-否): ") == "1"
    score = int(input("请输入能力评分(0-100): "))

    assistant = None

    if type_choice == "1":
        data_processing_speed = input("请输入数据处理速度: ")
        assistant = DataAnalysisAssistant(assistant_id, name, version, online, score, data_processing_speed)
    elif type_choice == "2":
        image_quality = input("请输入图片质量: ")
        assistant = ImageGenerationAssistant(assistant_id, name, version, online, score, image_quality)
    elif type_choice == "3":
        writing_style = input("请输入写作风格: ")
        assistant = TextGenerationAssistant(assistant_id, name, version, online, score, writing_style)
    elif type_choice == "4":
        supported_languages = int(input("请输入支持语言数量: "))
        assistant = TranslationAssistant(assistant_id, name, version, online, score, supported_languages)
    elif type_choice == "5":
        voice_type = input("请输入语音类型: ")
        assistant = VoiceAssistant(assistant_id, name, version, online, score, voice_type)
    else:
        print("❌ 无效的类型选择。")
        return

    manager.add_assistant(assistant)


def main():
    """主程序"""
    manager = AIManager()

    while True:
        print("\n========== AI助手管理器 ==========")
        print("1. 查看所有AI助手列表")
        print("2. 根据ID查询助手详情")
        print("3. 添加新的AI助手")
        print("4. 根据ID修改助手信息")
        print("5. 删除AI助手（按ID）")
        print("6. 启动AI助手服务")
        print("7. 停止AI助手服务")
        print("8. 为AI助手分配任务")
        print("9. 显示系统统计信息")
        print("0. 退出系统")
        print("===================================")

        choice = input("请选择操作: ").strip()

        if choice == "1":
            manager.list_all_assistants()
        elif choice == "2":
            assistant_id = input("请输入要查询的AI助手ID: ")
            manager.find_assistant_by_id(assistant_id)
        elif choice == "3":
            add_new_assistant(manager)
        elif choice == "4":
            assistant_id = input("请输入要修改的AI助手ID: ")
            print("可修改属性列表为：name, type, version, online, score")
            update_input = input("请输入要修改的属性和值，用空格分割: ").split()
            if len(update_input) >= 2:
                manager.update_assistant(assistant_id, update_input[0], update_input[1])
            else:
                print("❌ 输入格式错误，请按'属性 值'格式输入。")
        elif choice == "5":
            assistant_id = input("请输入要删除的AI助手ID: ")
            manager.delete_assistant(assistant_id)
        elif choice == "6":
            assistant_id = input("请输入要启动的AI助手ID: ")
            manager.start_assistant(assistant_id)
        elif choice == "7":
            assistant_id = input("请输入要停止的AI助手ID: ")
            manager.stop_assistant(assistant_id)
        elif choice == "8":
            assistant_id = input("请输入目标AI助手ID: ")
            task = input("请输入任务内容: ")
            manager.assign_task(assistant_id, task)
        elif choice == "9":
            manager.show_statistics()
        elif choice == "0":
            print("感谢使用AI助手管理器，再见！")
            break
        else:
            print("❌ 无效选择，请重新输入。")


if __name__ == "__main__":
    main()